//
//  HJCancellationController.m
//  KaiChat
//
//  Created by lx on 2023/10/19.
//

#import "HJCancellationController.h"
#import "HJMinePresent.h"

@interface HJCancellationController ()

@end

@implementation HJCancellationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.title = @"Account Cancellation";
    
    UILabel *titleLabel = [UILabel lableWithSuperView:self.view font:UIFontMediumMake(20) color:UIColor.tj_333333Color title:@"《User Cancellation Information》" textAlignment:NSTextAlignmentCenter];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(KNavBarHight + 20);
        make.centerX.offset(0);
    }];
    
    UILabel *subTitleLabel = [UILabel lableWithSuperView:self.view font:UIFontMediumMake(16) color:UIColor.tj_333333Color title:@"For dear users" textAlignment:NSTextAlignmentCenter];
    [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(20);
        make.left.offset(leftRightMargin);
    }];
    
    UILabel *tipContentLabel = [UILabel lableWithSuperView:self.view font:UIFontMake(14) color:UIColor.tj_333333Color title:@"lf you choose to cancel your account\n1. Account login and transaction funciions will nolonger provide services:\n2. All information of the account will be anonymizedand deleted after 7 days;\n3. Once the account is Account Cancellation, theaccount can no longer be used in any way, and theemail address bound to the account canhot beused for re-registration or binding." textAlignment:NSTextAlignmentLeft];
    tipContentLabel.numberOfLines = 0;
    tipContentLabel.attributedText = [self attributedString:tipContentLabel.text color:UIColor.tj_868391Color rangeString:@"lf you choose to cancel your account" rangeColor:UIColor.tj_333333Color];
    [tipContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(subTitleLabel.mas_bottom).offset(16);
        make.left.right.inset(leftRightMargin);
    }];
    
    UILabel *noteContentLabel = [UILabel lableWithSuperView:self.view font:UIFontMake(14) color:UIColor.tj_333333Color title:@"Please note:\n1. Your Kai account's personal data and historicalinformation (including nickname, avatar, messagehistory and photos) will not be retrieved;\n2. When you log out of your Kai accou nt, pleasebackup your wallet mnemonic/private kel/ inadvance." textAlignment:NSTextAlignmentLeft];
    noteContentLabel.numberOfLines = 0;
    noteContentLabel.attributedText = [self attributedString:noteContentLabel.text color:UIColor.tj_868391Color rangeString:@"Please note:" rangeColor:UIColor.tj_333333Color];
    [noteContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tipContentLabel.mas_bottom).offset(16);
        make.left.right.inset(leftRightMargin);
    }];

    HJStyle1Button *cancellationButton = [HJStyle1Button buttonWithSuperView:self.view font:UIFontMediumMake(14) color:nil title:@"Cancellation！"];
    [cancellationButton addTarget:self action:@selector(didClickCancellationButton) forControlEvents:UIControlEventTouchUpInside];
    [cancellationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(leftRightMargin);
        make.height.offset(buttonHeight);
        make.bottom.inset(10 + TabbarSafeBottomMargin);
    }];
}


- (NSAttributedString *)attributedString:(NSString *)string  color:(UIColor *)color rangeString:(NSString *)rangeString rangeColor:(UIColor *)rangeColor {
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 3;
    paragraphStyle.paragraphSpacing = 10;
    paragraphStyle.alignment = NSTextAlignmentLeft;

    NSDictionary *attributeDict = @{
        NSFontAttributeName: [UIFont systemFontOfSize:14],
        NSForegroundColorAttributeName:color,
        NSParagraphStyleAttributeName:paragraphStyle
    };
    
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:string attributes:attributeDict];
    [attributeStr addAttributes:@{
            NSForegroundColorAttributeName: rangeColor,
        } range:[string rangeOfString:rangeString]];
    return attributeStr;
}

- (void)didClickCancellationButton {
    [HJHUD showLoadingInView:self.view];
    [HJMinePresent revokedComplete:^(NSError * _Nullable error, NSString *message) {
        if (!error) {
            [HJHUD showMessage:message];
        }
    }];
}

@end
